package com.acwing.partition10;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author `RKC`
 * @date 2021/12/2 10:04
 */
public class AC905区间选点 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int[][] intervals = new int[n][2];
        for (int i = 0; i < n; i++) {
            s = reader.readLine().split(" ");
            intervals[i][0] = Integer.parseInt(s[0]);
            intervals[i][1] = Integer.parseInt(s[1]);
        }
        writer.write(greedy(intervals) + "\n");
        writer.flush();
    }

    private static int greedy(int[][] intervals) {
        //先对每个区间按照起点进行升序排列
        Arrays.sort(intervals, Comparator.comparingInt(o -> o[0]));
        int answer = 1;
        for (int i = 1; i < intervals.length; i++) {
            //如果当前区间和前面的区间没有任何交集，需要一个新的点；如果有交集，为了能使更多的区间包含这个点，区间的终点选择和前面区间的最小值
            if (intervals[i][0] > intervals[i - 1][1]) answer++;
            else intervals[i][1] = Math.min(intervals[i][1], intervals[i - 1][1]);
        }
        return answer;
    }
}
